<template>
    <div class="page_root" :key="queryUpdateFlag" data-page-name="整体进展" data-page-identification="m_ywye5y83e5">
        <a-spin :spinning="pageLoading.loading" :tip="pageLoading.tip">
            <!-- begin vid_nslycn2azl 自定义模板_301seah1im -->
            <div class="body">
                <div class="top-search">
                    <div class="border-div">
                        <a-row :gutter="24">
                            <a-col :span="6">
                                <a-form-item label="区域 ">
                                    <a-select
                                        v-model:value="state.filter.areaName"
                                        :options="state.areaList"
                                        show-search
                                        mode="multiple"
                                        allow-clear
                                        :max-tag-count="2"
                                        placeholder="请选择"
                                        :field-names="{ label: 'label', value: 'label' }"
                                        :filterOption="
                                            (input, option) => {
                                                return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                            }
                                        "
                                        @change="getData"
                                    />
                                </a-form-item>
                            </a-col>
                            <a-col :span="2">
                                <a-button type="primary" @click="resetData">重置</a-button>
                            </a-col>
                        </a-row>
                    </div>
                </div>
                <div class="content">
                    <div class="tip">
                        <span class="title-color-font">{{ totalCheck }}</span
                        >家进入验收阶段，<span class="title-color-font">{{ totalVerify }}</span
                        >家进入验证阶段，<span class="title-color-font">{{ totalRun }}</span
                        >家进入正式运行阶段，<span class="title-color-font">{{ totalTestRun }}</span
                        >家进入试运行阶段，<span class="title-color-font">{{ totalCollectionMapping }}</span
                        >家进入数据积累阶段
                    </div>
                    <a-table
                        bordered
                        :columns="columns"
                        :data-source="state.dataSource"
                        :loading="state.tableLoading"
                        :row-class-name="
                            (_record, index) => (index % 2 === 1 ? 'table-striped-even' : 'table-striped-odd')
                        "
                        :scroll="{ y: 540 }"
                        :pagination="false"
                    />
                </div>
            </div>
            <!-- end vid_nslycn2azl 自定义模板_301seah1im -->
        </a-spin>
    </div>
</template>
<script setup lang="tsx">
    import {
        h,
        ref,
        reactive,
        toRaw,
        markRaw,
        watch,
        computed,
        onBeforeMount,
        onMounted,
        onBeforeUnmount,
        onUnmounted,
        onActivated,
        onDeactivated
    } from 'vue'
    import { useRoute, useRouter } from 'vue-router'
    const router = useRouter()
    const route = useRoute()
    import { get, post, put, del, request, requestWithHeaders } from '@/utils/http/Axios'
    import {
        cloneDeep,
        localGet,
        merge,
        getDifferenceArray,
        traversalTreeStructure,
        checkCaseCondition,
        renderStringInTemplate,
        handleBreadcrumbJump,
        throttle,
        permission,
        getComponentParamsValue
    } from '@/utils/index'
    import { isNullOrEmpty, isEmptyArr, isNullOrUnDef, isContained, isArray, isEmpty, isObject } from '@/utils/is'
    import dayjs from 'dayjs'
    import { getPagePcChartsDataSourceConvert } from '@/utils/chart'
    import { message, notification, Modal } from 'ant-design-vue'
    import {
        propertyFormatByNumber,
        propertyFormatByPercentage,
        propertyFormatByDate,
        parseSubFromDataList
    } from '@/utils/format'
    import colorTheme from '@/design/custom-theme.json'
    /*** PUBLISH_EXEGESIS ***
 import UserTableRecords from '@/model/UserTableRecords';
 import { getAppBaseUrl } from '@/utils/index';
 import { sendToken } from "@/hooks/useIframeToken";
 import { useSystemStore } from "@/store/modules/system";
 const systemStore = useSystemStore();
 *** PUBLISH_EXEGESIS ***/

    // 获取传入的流程ID和组件参数
    const props = defineProps({
        'processInstanceId': {
            type: [String, Number, Boolean],
            default: undefined
        },
        'a': {
            type: [String],
            default: undefined
        }
    })
    const immediateWatch = (source, callback) => {
        watch(source, callback, { deep: true, immediate: true })
    }

    /* -------------------------- 属性定义 -------------------------- */

    const setTimeOutList = []
    const pageLoading = reactive({
        loading: false,
        tip: undefined
    })
    const authInfo = localGet('app-user-store')

    // 处理校验
    const setSubFormName = (parentInfo, name) => {
        return [parentInfo.parents, parentInfo.cycleIndex, name]
    }

    /* ========================== 属性定义 ========================== */

    /* -------------------------- 元素数据引用 -------------------------- */

    /* ========================== 元素数据引用 ========================== */

    /* -------------------------- 页面数据 -------------------------- */

    /* ========================== 页面数据 ========================== */

    /* -------------------------- 响应 -------------------------- */

    /* ========================== 响应 ========================== */

    /* -------------------------- 函数 -------------------------- */

    /* ========================== 函数 ========================== */

    /* -------------------------- 页面参数 -------------------------- */

    const pageParameter_state = reactive({
        'processInstanceId': props.processInstanceId ?? route.query.processInstanceId
    })

    /* ========================== 页面参数 ========================== */

    /* -------------------------- 组件事件处理方法 -------------------------- */

    // ---------------------------- 组件数据同步 ----------------------------

    // ============================ 组件数据同步 ============================

    /* ========================== 组件事件处理方法 ========================== */

    /* -------------------------- 生命周期 -------------------------- */
    // 用于参数变更后重新执行自定义指令
    const queryUpdateFlag = ref(0)
    onMounted(() => {})

    onUnmounted(() => {
        // 销毁定时器
        setTimeOutList.forEach(({ repeat, timer }) => {
            repeat ? clearInterval(timer) : clearTimeout(timer)
        })
    })

    /* ========================== 生命周期 ========================== */

    /* -------------------------- 数据关联处理 -------------------------- */

    /* -------------------------- 表单数据同步 -------------------------- */
    /* ========================== 表单数据同步 ========================== */

    /* ========================== 数据关联处理 ========================== */

    /* -------------------------- 不同组件自定义的处理逻辑 -------------------------- */

    /* ========================== 不同组件自定义的处理逻辑 ========================== */

    // ================================定制化逻辑========================================
    // 仅当组件被激活时，才执行数据请求
    // onActivated( () => {
    //     getAreaList()
    // })
    onMounted(() => {
        getAreaList()
        getData()
    })
    const state = reactive({
        filter: {
            areaName: []
        },
        tableLoading: false,
        areaList: [],
        dataSource: []
    })
    // 区域
    function getAreaList() {
        get('/solution-ppm/api/v2/built-in-system-ppm/work_order/area_info').then(data => {
            if (data.code !== 200) {
                message.error(data.message)
                return
            }
            state.areaList = data.data.map(item => {
                return {
                    label: item.areaName,
                    value: item.areaCode
                }
            })
        })
    }
    const totalCheck = ref(0)
    const totalVerify = ref(0)
    const totalRun = ref(0)
    const totalTestRun = ref(0)
    const totalCollectionMapping = ref(0)
    let isCalculated = false; // 标志变量，确保总计数据只计算一次
    function getData() {
        state.tableLoading = true;
        post('/solution-ppm/api/v2/built-in-system-ppm/project_progress/whole_progress/search', state.filter)
            .then(data => {
                if (data.code !== 200) {
                    state.dataSource = [];
                    return;
                }
                state.dataSource = data.data;

                // 只在第一次请求时计算总数
                if (!isCalculated) {
                    isCalculated = true;
                    totalCheck.value = 0;
                    totalVerify.value = 0;
                    totalRun.value = 0;
                    totalTestRun.value = 0;
                    totalCollectionMapping.value = 0;

                    data.data.forEach(item => {
                        totalCheck.value += item.check;
                        totalVerify.value += item.verify;
                        totalRun.value += item.run;
                        totalTestRun.value += item.testRun;
                        totalCollectionMapping.value += item.collectionMapping;
                    });
                }
            })
            .finally(() => {
                state.tableLoading = false;
            });
    }
    function resetData() {
        state.filter.areaName = []
        getData()
    }
    const columns = ref([
        {
            title: '区域',
            align: 'center',
            dataIndex: 'areaName'
        },
        {
            title: '数据积累',
            align: 'center',
            dataIndex: 'collectionMapping'
        },
        {
            title: '自学习表数据确认',
            align: 'center',
            dataIndex: 'processingTableConfirm'
        },
        {
            title: '数据建模',
            align: 'center',
            dataIndex: 'model'
        },
        {
            title: '试运行',
            align: 'center',
            dataIndex: 'testRun'
        },
        {
            title: '正式运行',
            align: 'center',
            dataIndex: 'run'
        },
        {
            title: '验证',
            align: 'center',
            dataIndex: 'verify'
        },
        {
            title: '验收',
            align: 'center',
            dataIndex: 'check'
        },
        {
            title: '验收完成',
            align: 'center',
            dataIndex: 'checkFinish'
        },
        {
            title: '合计',
            align: 'center',
            dataIndex: 'total'
        }
    ])
</script>
<style lang="less" scoped>
    .page_root {
        width: 100%;
        height: 100%;
        overflow: auto;
    }
    .page_root :deep(.@{ant-prefix}-spin-nested-loading),
    .page_root :deep(.@{ant-prefix}-spin-container) {
        height: 100%;
    }
    .page_root :deep(.@{ant-prefix}-spin-container .@{ant-prefix}-table-wrapper) {
        display: flex;
        flex-flow: column nowrap;
        justify-content: flex-start;
    }
    .page_root :deep(.@{ant-prefix}-table) {
        flex: auto;
        overflow: auto;
    }
    .table-moreBtn_down {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        width: 100px;
    }

    .table-moreBtn_menu :deep(.table-moreBtn_menu-item):hover {
        background: #ebf1ff;
    }

    /*  表格树结构样式处理，展开按钮层级增加*/
    :deep(.@{ant-prefix}-table-row-expand-icon) {
        z-index: 1;
    }
    /*  表格树结构 由于每个表格项采用自定义组件，使用绝对定位布局，开启树结构导致显示异常，暂时使用层级定位位置 */
    :deep(.@{ant-prefix}-table-row-level-1 .@{ant-prefix}-table-cell-with-append .cell-wrapper-left) {
        left: 15px !important;
        width: calc(100% - 15px);
    }
    :deep(.@{ant-prefix}-table-row-level-2 .@{ant-prefix}-table-cell-with-append .cell-wrapper-left) {
        left: 30px !important;
        width: calc(100% - 30px);
    }
    :deep(.@{ant-prefix}-table-row-level-3 .@{ant-prefix}-table-cell-with-append .cell-wrapper-left) {
        left: 45px !important;
        width: calc(100% - 45px);
    }
    :deep(.@{ant-prefix}-table-row-level-4 .@{ant-prefix}-table-cell-with-append .cell-wrapper-left) {
        left: 60px !important;
        width: calc(100% - 60px);
    }

    /* 穿梭框改变默认样式，为根据组件样式控制左右栏宽度。 */
    :deep(.@{ant-prefix}-transfer-list) {
        height: 100%;
        width: 50%;
    }
    /*
    整体进展
    */
    .page_root {
        overflow: hidden;
        height: 100%;
    }
    .body {
        height: 100%;
    }
    .top-search {
        background-color: #fff;
        padding: 24px;
    }
    .border-div {
        padding-bottom: 16px;
        border-bottom: 1px solid #d9d9d9;
    }
    .top-search :deep(.ant3-row) {
        height: 32px;
    }
    .top-search :deep(.ant3-col) {
        height: 32px;
    }
    .content {
        padding: 0 24px;
        height: 100%;
        background-color: #fff;
    }
    .content :deep(.@{ant-prefix}-table-thead) > tr > th {
        background: #3875ff;
        color: #fff;
        font-weight: 600;
        padding: 8px 16px;
        border-right: 1px solid #d9d9d9 !important;
        position: relative;
    }
    .content :deep(.@{ant-prefix}-table-tbody) tr > td {
        font-size: 14px;
        font-family: arial, helvetica, 'microsoft yahei';
        font-weight: 400;
        color: #262626;
        border-bottom: 1px solid #d9d9d9;
        padding: 8px 16px;
        word-break: break-all;
    }
    .content :deep(.table-striped-even) td {
        background-color: #f8fafc;
    }
    .tip {
        height: 40px;
        padding: 9px 16px;
        background: #ebf1ff;
        border: 1px solid #3875ff;
        border-radius: 4px;
        font-size: 14px;
        color: #262626;
        letter-spacing: 0;
        line-height: 22px;
        font-weight: 400;
        margin-bottom: 16px;
    }
    .title-color-font {
        font-size: 16px;
        color: #3875ff;
        letter-spacing: 0;
        line-height: 22px;
        font-weight: 600;
    }
    /*
    整体进展
    */
</style>
